<template>
  <a-modal
    title="评价"
    :width="640"
    :maskClosable = "false"
    :visible="visible"
    :confirmLoading="loading"
    @ok="ok"
    @cancel="() => { $emit('cancel') }"
  >
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="layout">
        <a-form-item label="意见">
          <a-select :default-value="1" :value="model.advise" style="width: 180px" @change="handleAdviseChange">
            <a-select-option v-for="(item, index) in adviseOptions" :key="index" :value="item.value">
              {{item.title}}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="补充说明">
          <a-textarea
                  :value="model.comment"
                  placeholder="补充说明"
                  :auto-size="{ minRows: 3, maxRows: 5 }"
                  @change="handleCommentChange"
          />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

export default {
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    loading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    }
  },
  data () {
    return {
      form: this.$form.createForm(this),
      adviseOptions: [{value: 0, title: '不推荐'}, {value: 1, title: '建议面试'}, {value: 2, title: '待定'}],
      layout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 13 }
        }
      }
    }
  },
  methods: {
    handleAdviseChange(selected) {
      this.model.advise = selected
    },
    handleCommentChange(e) {
      this.model.comment = e.target.value
    },
    ok() {
      this.$emit('ok', this.model)
    }
  }
}
</script>
